package com.wbao.dianniu.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.customView.NoDoubleClickListener;
import com.wbao.dianniu.listener.IReportListener;
import com.wbao.dianniu.logical.Const;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.manager.ReportManager;
import com.wbao.dianniu.utils.Notification;
import com.wbao.dianniu.R;

/**
 * 举报
 *
 * @author yejianjun
 */
public class ReportActivity extends BaseActivity implements IReportListener {

    private RadioGroup radioGroup;
    private ReportManager manager;
    private Button btn_submit;
//    private final int REPORT_TYPE = 1;
    private int objectId;
    private int type;
    private EditText descET;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentLayout(R.layout.activity_report, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        setTitleName("举报");
        getBackView().setImageResource(R.drawable.cancel_res_icon);
        btn_submit = findViewById(R.id.report_submit);
        radioGroup = findViewById(R.id.report_radiogroup);
        descET = findViewById(R.id.reason_desc_et);
        manager = new ReportManager(this);
        manager.addReportListener(this);
        type = getIntent().getIntExtra(Const.INTENT_REPORT_TYPE, 0);
        objectId = getIntent().getIntExtra(Const.INTENT_REPORT_OBJECTID, 0);
        btn_submit.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                if (-1 == radioGroup.getCheckedRadioButtonId()) {
                    Notification.toast(ReportActivity.this, "选择举报原因");
                    return;
                }
                RadioButton radioButton = findViewById(radioGroup.getCheckedRadioButtonId());
                manager.report(GlobalContext.getAccountId(), type, objectId, radioButton.getText().toString(), descET.getText().toString().trim());
            }
        });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
        /*case R.id.report_submit:
			if(-1 ==radioGroup.getCheckedRadioButtonId()){
				Notification.toast(this, "选择举报原因");
				return;
			}
			RadioButton radioButton = (RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());
			manager.report(GlobalContext.getAccountId(), REPORT_TYPE, objectId, radioButton.getText().toString(), descET.getText().toString().trim());
			break;*/

            default:
                break;
        }
    }

    @Override
    public void onReportFailure(int errorCode, String errorMsg) {
    }

    @Override
    public void onReportSuccess() {
        Notification.toast(this, getResources().getString(R.string.report_success));
        finish();
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != manager) {
            manager.removeReportListener(this);
        }
    }
}
